﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using InsideDL.MISService;
using InsideDL.MISControl;
using InsideDL.MISData;

namespace InsideDL
{
    public partial class frmIG002 : MISControl.frmMatrix
    {
        protected EXLAPP exlAPP = null;

        protected string profitShtName = string.Empty;

        public frmIG002()
        {
            InitializeComponent();

            Utility.LoadConfigValue("frmIG002");
            this.controlList = new List<ucSelFileOrPath>
            {
                ucRevenues,ucProfit,ucCompiled
            };
            ucExecute1.ExecuteClick += new EventHandler(ucClickFacade);
            ucExecute_Exit.ExecuteClick += new EventHandler(ucClickFacade);

            profitShtName = Utility.GetTWYM();
        }

        protected override void execute()
        {
            if (base.Vaildation().Equals(false))
            { return; }

            exlAPP = new EXLAPP();
            string revenues;
            #region 先取得各累收支中的營業外收支的欄位值。
            exlAPP.OpenFile(ucRevenues.Txt);
            revenues = exlAPP.GetSheetRangeValue(
                Utility.GetConfigValue("OtherSheet")
                , Utility.GetNewRange(Utility.GetConfigValue("OtherCol")
                                    , Utility.GetConfigValue("OtherRow"))
                    );
            exlAPP.CloseFile();
            #endregion

            exlAPP.OpenFile(ucCompiled.Txt);//產險資料彙整工作表
            exlAPP.OpenFile(ucProfit.Txt);//核保利潤
            
            exlAPP.CopyPaste(Utility.GetTWYM()
                , Utility.GetConfigValue("sourceRrnge")
                , Utility.GetConfigValue("TargetSht")
                , Utility.GetNewRange(Utility.GetConfigValue("TargetCol")
                                    , Utility.GetConfigValue("TargetRow")));

            exlAPP.SetRangeValue(Utility.GetConfigValue("RevenuesSht")
                , Utility.GetNewRange(Utility.GetConfigValue("RevenuesCol")
                                    , Utility.GetConfigValue("RevenuesRow"))
                                    , revenues);
            exlAPP.SaveCloseXLS();
            exlAPP = null;
            showMessage(this.Text, "完成！");  


        }
    }
}
